/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Validation;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author sunwei
 */
public class ContactNumberValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {

        String contactNum = (String) value;

        try {
            long num = Long.parseLong(contactNum);
        } catch (NumberFormatException e) {
            FacesMessage message = new FacesMessage();
            message.setDetail("Contact number is not valid");
            message.setSummary("Contact number is not valid");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            throw new ValidatorException(message);
        }
    }
}
